In [ ]:
import numpy as np
from IPython.display import display
from bqplot import *
In [ ]:
size = 100
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(100) * 100.0)
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
ax_x = Axis(label='X', scale=x_sc, grid_lines='solid')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', grid_lines='solid')
line = Lines(x=x_data, y=x_data, scales={'x': x_sc, 'y': y_sc})
fig = Figure(axes=[ax_x, ax_y], marks=[line])
display(fig)
In [ ]:
dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')
size = len(dates)
prices = 100 + 5 * np.cumsum(np.random.randn(size))
In [ ]:
dt_x = DateScale()
lin_y = LinearScale()
x_ax = Axis(label='Date', scale=dt_x, tick_format='%b-%d', grid_lines='solid')
x_ay = Axis(label=('Price'), scale=lin_y, orientation='vertical', tick_format='0.0f', grid_lines='solid')
lc = Lines(x=dates, y=prices, scales={'x': dt_x, 'y': lin_y}, colors=['blue'])
fig = Figure(marks=[lc], axes=[x_ax, x_ay], fig_color='lightgreen')
display(fig)
In [ ]:
fig.fig_color = 'Black'
In [ ]:
sc_x = LinearScale()
sc_y = LinearScale()
scatter = Scatter(x=x_data, y=y_data, scales={'x': sc_x, 'y': sc_y}, default_colors=['blue'])
ax_x = Axis(label='Test X', scale=sc_x)
ax_y = Axis(label='Test Y', scale=sc_y, orientation='vertical', tick_format='0.2f')
fig = Figure(axes=[ax_x, ax_y], marks=[scatter])
display(fig)
In [ ]:
scale_x = LinearScale()
scale_y = LinearScale()
hist = Hist(sample=y_data, scales={'sample': scale_x, 'count': scale_y})
ax_x = Axis(label='X', scale=scale_x, tick_format='0.2f')
ax_y = Axis(label='Y', scale=scale_y, orientation='vertical', grid_lines='solid')
fig = Figure(axes=[ax_x, ax_y], marks=[hist])
display(fig)
In [ ]:
sc_x1 = OrdinalScale()
sc_y1 = LinearScale()
bar_x = Axis(label='X', scale=sc_x1)
bar_y = Axis(label='Y', scale=sc_y1, orientation='vertical', tick_format='0.0f', grid_lines='solid')
bar_chart = Bars(x=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U'],
y=np.abs(y_data[:20]), scales={'x': sc_x1, 'y': sc_y1})
fig = Figure(axes=[bar_x, bar_y], marks=[bar_chart], padding_x=0)
display(fig)